<!-- 服务端 -->
<?php

// $username = $_POST["username"];
// $password = $_POST["password"];

session_start();
if (isset($_POST["username"]) && isset($_POST["password"])) {
    $username = $_POST["username"];
    $password = $_POST["password"];
    if (
        // strlen 获取字符串长度  
        //  trim去除字符串的首尾处的空白符  
        //  isset判断一个变量是否已设置,即变量已被声明
        strlen(trim($username)) >= 0 && strlen(trim($password)) >= 6 &&
        !isset($_SESSION["username"])
    ) {
        $_SESSION["username"] = $username;
        echo "<h1>欢迎" . $username . "你已经成功登录</h1>";
    } else if (
        strlen(trim($username)) > 0 && strlen(trim($password)) >= 6 &&
        $_SESSION["username"]
    ) {
        echo "<h1>欢迎" . $username . "你已经登录过</h1>";
        unset($_SESSION["username"]);
    } else {
        echo "<h1>登录失败,用户名不符合规范</h1>";
    }
} else {
    echo "<h1>非法登录</h1>";
}

echo "该用户${username}已经登录,密码${password}";